package v1alpha1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type JVMDruidChaosSpec struct {
	// ContainerSelector specifies the target for injection
	ContainerSelector `json:",inline"`

	// BladeCommonSpec contains basic spec of blade chaos action
	// +optional
	BladeCommonSpec `json:",inline"`

	// Duration represents the duration of the chaos
	// +optional
	Duration *string `json:"duration,omitempty"`

	// Action defines the specific jvm http action.
	Action JVMDruidAction `json:"action"`

	// RemoteCluster represents the remote cluster where the chaos will be deployed
	// +optional
	RemoteCluster string `json:"remoteCluster,omitempty"`
}

type JVMDruidAction string

// connectionpoolfull
const (
	JVMDruidActionConnectionPoolFull JVMDruidAction = "connectionpoolfull"
)

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
// +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
// +chaos-mesh:experiment

type JVMDruidChaos struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   JVMDruidChaosSpec `json:"spec"`
	Status BladeChaosStatus  `json:"status,omitempty"`
}

var _ InnerObjectWithCustomStatus = (*JVMDruidChaos)(nil)
var _ InnerObjectWithSelector = (*JVMDruidChaos)(nil)
var _ InnerObject = (*JVMDruidChaos)(nil)

func init() {
	SchemeBuilder.Register(&JVMDruidChaos{}, &JVMDruidChaosList{})
}

// GetSelectorSpecs is a getter for selectors
func (obj *JVMDruidChaos) GetSelectorSpecs() map[string]interface{} {
	return map[string]interface{}{
		".": &obj.Spec.ContainerSelector,
	}
}

func (obj *JVMDruidChaos) GetCustomStatus() interface{} {
	return &obj.Status.BladeChaosCustomStatus
}
